local qiai = fk.CreateSkill {
  name = "mini__qiai",
}

Fk:loadTranslationTable{
  ["mini__qiai"] = "七哀",
  [":mini__qiai"] = "出牌阶段限一次，你可以将一张非基本牌交给一名其他角色，你选择一项：1.回复1点体力；2.摸两张牌。"..
  "然后你可以令其执行另一项效果。",

  ["#mini__qiai"] = "七哀：将一张非基本牌交给一名角色，你回复体力或摸牌，然后可以令其执行另一项",
  ["#mini__qiai-invoke"] = "七哀：是否令 %dest %arg？",

  ["$mini__qiai1"] = "蟋蟀夹岸鸣，孤鸟翩翩飞。",
  ["$mini__qiai2"] = "征夫心多怀，恻怆令吾悲。",
}

qiai:addEffect("active", {
  anim_type = "support",
  prompt = "#mini__qiai",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(qiai.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type ~= Card.TypeBasic
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:moveCardTo(effect.cards, Player.Hand, target, fk.ReasonGive, qiai.name, nil, true, player)
    if player.dead then return end
    local choices = { "draw2" }
    if player:isWounded() then
      table.insert(choices, 1, "recover")
    end
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = qiai.name,
    })
    if choice == "draw2" then
      player:drawCards(2, qiai.name)
    else
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = qiai.name,
      }
    end
    if player.dead or target.dead then return end
    if choice == "draw2" then
      if target:isWounded() and
        room:askToSkillInvoke(player, {
          skill_name = qiai.name,
          prompt = "#mini__qiai-invoke::"..target.id..":recover",
        }) then
        room:recover{
          who = target,
          num = 1,
          recoverBy = player,
          skillName = qiai.name,
        }
      end
    elseif room:askToSkillInvoke(player, {
        skill_name = qiai.name,
        prompt = "#mini__qiai-invoke::"..target.id..":draw2",
      }) then
      target:drawCards(2, qiai.name)
    end
  end,
})

return qiai
